thread a config throughout
authorSteve Klabnik <steve@steveklabnik.com>
Mon, 3 Oct 2016 20:40:57 +0000 (16:40 -0400)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 7 Oct 2016 17:57:56 +0000 (10:57 -0700)
25 files changed:
src/cargo/core/dependency.rs
src/cargo/core/package.rs
src/cargo/core/registry.rs
src/cargo/core/resolver/mod.rs
src/cargo/core/source.rs
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_fetch.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/ops/cargo_install.rs
src/cargo/ops/cargo_output_metadata.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/custom_build.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/job_queue.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/ops/resolve.rs
src/cargo/sources/directory.rs
src/cargo/sources/git/source.rs
src/cargo/sources/path.rs
src/cargo/sources/registry/index.rs
src/cargo/sources/registry/mod.rs
src/cargo/sources/replaced.rs
src/cargo/util/toml.rs
tests/resolve.rs

index be8ff5d903f1fe705f242663743d1b5e262668ce..61167a8b4f5fe845afd094a8c0f4e1240863d57b 100644 (file)
@@ -7,7 +7,7 @@ use semver::ReqParseError;
 use rustc_serialize::{Encoder, Encodable};
 
 use core::{SourceId, Summary, PackageId};
-use util::{CargoError, CargoResult, Cfg, CfgExpr, ChainError, human};
+use util::{CargoError, CargoResult, Cfg, CfgExpr, ChainError, human, Config};
 
 /// Information about a dependency requested by a Cargo manifest.
 /// Cheap to copy.
@@ -90,7 +90,8 @@ impl DependencyInner {
     /// Attempt to create a `Dependency` from an entry in the manifest.
     pub fn parse(name: &str,
                  version: Option<&str>,
-                 source_id: &SourceId) -> CargoResult<DependencyInner> {
+                 source_id: &SourceId,
+                 _config: &Config) -> CargoResult<DependencyInner> {
         let (specified_req, version_req) = match version {
             Some(v) => (true, try!(DependencyInner::parse_with_deprecated(v))),
             None => (false, VersionReq::any())
@@ -233,8 +234,9 @@ impl Dependency {
     /// Attempt to create a `Dependency` from an entry in the manifest.
     pub fn parse(name: &str,
                  version: Option<&str>,
-                 source_id: &SourceId) -> CargoResult<Dependency> {
-        DependencyInner::parse(name, version, source_id).map(|di| {
+                 source_id: &SourceId,
+                 config: &Config) -> CargoResult<Dependency> {
+        DependencyInner::parse(name, version, source_id, config).map(|di| {
             di.into_dependency()
         })
     }
index da14b04fc33c6d36b0328b3cfad981a337348770..0235b619285f1ca024edbef5b6c8e88a82322cbc 100644 (file)
@@ -156,7 +156,7 @@ impl<'cfg> PackageSet<'cfg> {
         Box::new(self.packages.iter().map(|&(ref p, _)| p))
     }
 
-    pub fn get(&self, id: &PackageId) -> CargoResult<&Package> {
+    pub fn get(&self, id: &PackageId, config: &Config) -> CargoResult<&Package> {
         let slot = try!(self.packages.iter().find(|p| p.0 == *id).chain_error(|| {
             internal(format!("couldn't find `{}` in package set", id))
         }));
@@ -168,7 +168,7 @@ impl<'cfg> PackageSet<'cfg> {
         let source = try!(sources.get_mut(id.source_id()).chain_error(|| {
             internal(format!("couldn't find source for `{}`", id))
         }));
-        let pkg = try!(source.download(id).chain_error(|| {
+        let pkg = try!(source.download(id, config).chain_error(|| {
             human("unable to get packages from source")
         }));
         assert!(slot.fill(pkg).is_ok());
index 79089ee4d7efc66efcd437ab8c0e02e246874f37..5aa11abfda7818f2cc980204710e59e609e2e67b 100644 (file)
@@ -10,7 +10,7 @@ use sources::config::SourceConfigMap;
 /// See also `core::Source`.
 pub trait Registry {
     /// Attempt to find the packages that match a dependency request.
-    fn query(&mut self, name: &Dependency) -> CargoResult<Vec<Summary>>;
+    fn query(&mut self, name: &Dependency, config: &Config) -> CargoResult<Vec<Summary>>;
 
     /// Returns whether or not this registry will return summaries with
     /// checksums listed.
@@ -22,22 +22,22 @@ pub trait Registry {
 }
 
 impl Registry for Vec<Summary> {
-    fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+    fn query(&mut self, dep: &Dependency, _config: &Config) -> CargoResult<Vec<Summary>> {
         Ok(self.iter().filter(|summary| dep.matches(*summary))
                .cloned().collect())
     }
 }
 
 impl Registry for Vec<Package> {
-    fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+    fn query(&mut self, dep: &Dependency, _config: &Config) -> CargoResult<Vec<Summary>> {
         Ok(self.iter().filter(|pkg| dep.matches(pkg.summary()))
                .map(|pkg| pkg.summary().clone()).collect())
     }
 }
 
 impl<'a, T: ?Sized + Registry + 'a> Registry for Box<T> {
-    fn query(&mut self, name: &Dependency) -> CargoResult<Vec<Summary>> {
-        (**self).query(name)
+    fn query(&mut self, name: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
+        (**self).query(name, config)
     }
 }
 
@@ -364,7 +364,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
 #[cfg(test)]
 pub mod test {
     use core::{Summary, Registry, Dependency};
-    use util::{CargoResult};
+    use util::{CargoResult, Config};
 
     pub struct RegistryBuilder {
         summaries: Vec<Summary>,
@@ -405,13 +405,13 @@ pub mod test {
     }
 
     impl Registry for RegistryBuilder {
-        fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+        fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
             debug!("querying; dep={:?}", dep);
 
             let overrides = self.query_overrides(dep);
 
             if overrides.is_empty() {
-                self.summaries.query(dep)
+                self.summaries.query(dep, config)
             } else {
                 Ok(overrides)
             }
index 7a9e953365a6283e73f375b154add2d1efd195f6..ed57a1a9b0bed809248fb6649080b13d3a64de8f 100644 (file)
@@ -55,7 +55,7 @@ use semver;
 
 use core::{PackageId, Registry, SourceId, Summary, Dependency};
 use core::PackageIdSpec;
-use util::{CargoResult, Graph, human, CargoError};
+use util::{CargoResult, Graph, human, CargoError, Config};
 use util::profile;
 use util::ChainError;
 use util::graph::{Nodes, Edges};
@@ -265,7 +265,8 @@ struct Context<'a> {
 /// Builds the list of all packages required to build the first argument.
 pub fn resolve(summaries: &[(Summary, Method)],
                replacements: &[(PackageIdSpec, Dependency)],
-               registry: &mut Registry) -> CargoResult<Resolve> {
+               registry: &mut Registry,
+               config: &Config) -> CargoResult<Resolve> {
     let cx = Context {
         resolve_graph: Graph::new(),
         resolve_features: HashMap::new(),
@@ -274,7 +275,7 @@ pub fn resolve(summaries: &[(Summary, Method)],
         replacements: replacements,
     };
     let _p = profile::start(format!("resolving"));
-    let cx = try!(activate_deps_loop(cx, registry, summaries));
+    let cx = try!(activate_deps_loop(cx, registry, summaries, config));
 
     let mut resolve = Resolve {
         graph: cx.resolve_graph,
@@ -305,7 +306,8 @@ fn activate(cx: &mut Context,
             registry: &mut Registry,
             parent: Option<&Rc<Summary>>,
             candidate: Candidate,
-            method: &Method)
+            method: &Method,
+            config: &Config)
             -> CargoResult<Option<DepsFrame>> {
     if let Some(parent) = parent {
         cx.resolve_graph.link(parent.package_id().clone(),
@@ -333,7 +335,7 @@ fn activate(cx: &mut Context,
         }
     };
 
-    let deps = try!(cx.build_deps(registry, &candidate, method));
+    let deps = try!(cx.build_deps(registry, &candidate, method, config));
 
     Ok(Some(DepsFrame {
         parent: candidate,
@@ -435,7 +437,8 @@ struct BacktrackFrame<'a> {
 /// dependency graph, cx.resolve is returned.
 fn activate_deps_loop<'a>(mut cx: Context<'a>,
                           registry: &mut Registry,
-                          summaries: &[(Summary, Method)])
+                          summaries: &[(Summary, Method)],
+                          config: &Config)
                           -> CargoResult<Context<'a>> {
     // Note that a `BinaryHeap` is used for the remaining dependencies that need
     // activation. This heap is sorted such that the "largest value" is the most
@@ -451,7 +454,7 @@ fn activate_deps_loop<'a>(mut cx: Context<'a>,
         let summary = Rc::new(summary.clone());
         let candidate = Candidate { summary: summary, replace: None };
         remaining_deps.extend(try!(activate(&mut cx, registry, None, candidate,
-                                            method)));
+                                            method, config)));
     }
 
     // Main resolution loop, this is the workhorse of the resolution algorithm.
@@ -545,7 +548,8 @@ fn activate_deps_loop<'a>(mut cx: Context<'a>,
                     None => return Err(activation_error(&cx, registry, &parent,
                                                         &dep,
                                                         &cx.prev_active(&dep),
-                                                        &candidates)),
+                                                        &candidates,
+                                                        config)),
                     Some(candidate) => candidate,
                 }
             }
@@ -559,7 +563,7 @@ fn activate_deps_loop<'a>(mut cx: Context<'a>,
         trace!("{}[{}]>{} trying {}", parent.name(), cur, dep.name(),
                candidate.summary.version());
         remaining_deps.extend(try!(activate(&mut cx, registry, Some(&parent),
-                                            candidate, &method)));
+                                            candidate, &method, config)));
     }
 
     Ok(cx)
@@ -595,7 +599,8 @@ fn activation_error(cx: &Context,
                     parent: &Summary,
                     dep: &Dependency,
                     prev_active: &[Rc<Summary>],
-                    candidates: &[Candidate]) -> Box<CargoError> {
+                    candidates: &[Candidate],
+                    config: &Config) -> Box<CargoError> {
     if candidates.len() > 0 {
         let mut msg = format!("failed to select a version for `{}` \
                                (required by `{}`):\n\
@@ -648,7 +653,7 @@ fn activation_error(cx: &Context,
     let mut msg = msg;
     let all_req = semver::VersionReq::parse("*").unwrap();
     let new_dep = dep.clone_inner().set_version_req(all_req).into_dependency();
-    let mut candidates = match registry.query(&new_dep) {
+    let mut candidates = match registry.query(&new_dep, config) {
         Ok(candidates) => candidates,
         Err(e) => return e,
     };
@@ -816,7 +821,8 @@ impl<'a> Context<'a> {
     fn build_deps(&mut self,
                   registry: &mut Registry,
                   candidate: &Summary,
-                  method: &Method) -> CargoResult<Vec<DepInfo>> {
+                  method: &Method,
+                  config: &Config) -> CargoResult<Vec<DepInfo>> {
         // First, figure out our set of dependencies based on the requsted set
         // of features. This also calculates what features we're going to enable
         // for our own dependencies.
@@ -825,7 +831,7 @@ impl<'a> Context<'a> {
         // Next, transform all dependencies into a list of possible candidates
         // which can satisfy that dependency.
         let mut deps = try!(deps.into_iter().map(|(dep, features)| {
-            let mut candidates = try!(self.query(registry, &dep));
+            let mut candidates = try!(self.query(registry, &dep, config));
             // When we attempt versions for a package, we'll want to start at
             // the maximum version and work our way down.
             candidates.sort_by(|a, b| {
@@ -851,8 +857,9 @@ impl<'a> Context<'a> {
     /// return.
     fn query(&self,
              registry: &mut Registry,
-             dep: &Dependency) -> CargoResult<Vec<Candidate>> {
-        let summaries = try!(registry.query(dep));
+             dep: &Dependency,
+             config: &Config) -> CargoResult<Vec<Candidate>> {
+        let summaries = try!(registry.query(dep, config));
         summaries.into_iter().map(Rc::new).map(|summary| {
             // get around lack of non-lexical lifetimes
             let summary2 = summary.clone();
@@ -865,7 +872,7 @@ impl<'a> Context<'a> {
                 Some(replacement) => replacement,
             };
 
-            let mut summaries = try!(registry.query(dep)).into_iter();
+            let mut summaries = try!(registry.query(dep, config)).into_iter();
             let s = try!(summaries.next().chain_error(|| {
                 human(format!("no matching package for override `{}` found\n\
                                location searched: {}\n\
index 4a46c19294d26677af0d5842604bf1a935caf069..b09d57ef93efee0849c3a3da8bf710f3a615b7e7 100644 (file)
@@ -27,7 +27,7 @@ pub trait Source: Registry {
 
     /// The download method fetches the full package for each name and
     /// version specified.
-    fn download(&mut self, package: &PackageId) -> CargoResult<Package>;
+    fn download(&mut self, package: &PackageId, config: &Config) -> CargoResult<Package>;
 
     /// Generates a unique string which represents the fingerprint of the
     /// current state of the source.
@@ -57,8 +57,8 @@ impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
         (**self).update()
     }
 
-    fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
-        (**self).download(id)
+    fn download(&mut self, id: &PackageId, config: &Config) -> CargoResult<Package> {
+        (**self).download(id, config)
     }
 
     fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {
index e19b37f116fc20ecd09930d532adc9b6382c15e5..6c50a90dc6b3a68a97deecb6265adb9ed4edaca8 100644 (file)
@@ -29,7 +29,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
     }
 
     let mut registry = try!(PackageRegistry::new(opts.config));
-    let resolve = try!(ops::resolve_ws(&mut registry, ws));
+    let resolve = try!(ops::resolve_ws(&mut registry, ws, opts.config));
     let packages = ops::get_resolved_packages(&resolve, registry);
 
     let profiles = try!(ws.current()).manifest().profiles();
@@ -47,7 +47,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
     for spec in opts.spec {
         // Translate the spec to a Package
         let pkgid = try!(resolve.query(spec));
-        let pkg = try!(packages.get(&pkgid));
+        let pkg = try!(packages.get(&pkgid, ws.config()));
 
         // Generate all relevant `Unit` targets for this package
         for target in pkg.targets() {
index 0767e9e467aafd96f912825cebc711b8065067c1..c8b50cd93b930b5f965a570233cd0ccb7df3ff8a 100644 (file)
@@ -118,7 +118,7 @@ pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
 
     // First, resolve the root_package's *listed* dependencies, as well as
     // downloading and updating all remotes and such.
-    let resolve = try!(ops::resolve_ws(&mut registry, ws));
+    let resolve = try!(ops::resolve_ws(&mut registry, ws, ws.config()));
 
     // Second, resolve with precisely what we're doing. Filter out
     // transitive dependencies if necessary, specify features, handle
@@ -143,7 +143,7 @@ pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
     let resolved_with_overrides =
             try!(ops::resolve_with_previous(&mut registry, ws,
                                             method, Some(&resolve), None,
-                                            &specs));
+                                            &specs, ws.config()));
 
     let packages = ops::get_resolved_packages(&resolved_with_overrides,
                                               registry);
@@ -190,7 +190,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
     };
 
     let to_builds = try!(pkgids.iter().map(|id| {
-        packages.get(id)
+        packages.get(id, config)
     }).collect::<CargoResult<Vec<_>>>());
 
     let mut general_targets = Vec::new();
index a0144c8f4729c3f2758821bbdc30d6bf0ffd37da..77634b9c83fbe29ffd5aeaf4b11f3a2d18dd41df 100644 (file)
@@ -6,10 +6,10 @@ use util::CargoResult;
 /// Executes `cargo fetch`.
 pub fn fetch<'a>(ws: &Workspace<'a>) -> CargoResult<(Resolve, PackageSet<'a>)> {
     let mut registry = try!(PackageRegistry::new(ws.config()));
-    let resolve = try!(ops::resolve_ws(&mut registry, ws));
+    let resolve = try!(ops::resolve_ws(&mut registry, ws, ws.config()));
     let packages = get_resolved_packages(&resolve, registry);
     for id in resolve.iter() {
-        try!(packages.get(id));
+        try!(packages.get(id, ws.config()));
     }
     Ok((resolve, packages))
 }
index 25e2204ba9e12dcc94dfff963b17188a23ea6e55..7758cc63c4d25aa1f4faf7ae8380a2f8b1eae24d 100644 (file)
@@ -19,7 +19,7 @@ pub fn generate_lockfile(ws: &Workspace) -> CargoResult<()> {
     let mut registry = try!(PackageRegistry::new(ws.config()));
     let resolve = try!(ops::resolve_with_previous(&mut registry, ws,
                                                   Method::Everything,
-                                                  None, None, &[]));
+                                                  None, None, &[], ws.config()));
     try!(ops::write_pkg_lockfile(ws, &resolve));
     Ok(())
 }
@@ -79,7 +79,8 @@ pub fn update_lockfile(ws: &Workspace, opts: &UpdateOptions)
                                                   Method::Everything,
                                                   Some(&previous_resolve),
                                                   Some(&to_avoid),
-                                                  &[]));
+                                                  &[],
+                                                  ws.config()));
 
     // Summarize what is changing for the user.
     let print_change = |status: &str, msg: String| {
index 616c7b351868020f2b6975175b00c4c44466af6f..91d44a4d4ffe55d076ca681c90bbd8e367ce35a2 100644 (file)
@@ -57,7 +57,7 @@ pub fn install(root: Option<&str>,
     let map = try!(SourceConfigMap::new(config));
     let (pkg, source) = if source_id.is_git() {
         try!(select_pkg(GitSource::new(source_id, config), source_id,
-                        krate, vers, &mut |git| git.read_packages()))
+                        krate, vers, config, &mut |git| git.read_packages()))
     } else if source_id.is_path() {
         let path = source_id.url().to_file_path().ok()
                             .expect("path sources must have a valid path");
@@ -68,11 +68,11 @@ pub fn install(root: Option<&str>,
                            specify an alternate source", path.display()))
         }));
         try!(select_pkg(PathSource::new(&path, source_id, config),
-                        source_id, krate, vers,
+                        source_id, krate, vers, config,
                         &mut |path| path.read_packages()))
     } else {
         try!(select_pkg(try!(map.load(source_id)),
-                        source_id, krate, vers,
+                        source_id, krate, vers, config,
                         &mut |_| Err(human("must specify a crate to install from \
                                             crates.io, or use --path or --git to \
                                             specify alternate source"))))
@@ -251,6 +251,7 @@ fn select_pkg<'a, T>(mut source: T,
                      source_id: &SourceId,
                      name: Option<&str>,
                      vers: Option<&str>,
+                     config: &Config,
                      list_all: &mut FnMut(&mut T) -> CargoResult<Vec<Package>>)
                      -> CargoResult<(Package, Box<Source + 'a>)>
     where T: Source + 'a
@@ -258,11 +259,11 @@ fn select_pkg<'a, T>(mut source: T,
     try!(source.update());
     match name {
         Some(name) => {
-            let dep = try!(Dependency::parse(name, vers, source_id));
-            let deps = try!(source.query(&dep));
+            let dep = try!(Dependency::parse(name, vers, source_id, config));
+            let deps = try!(source.query(&dep, config));
             match deps.iter().map(|p| p.package_id()).max() {
                 Some(pkgid) => {
-                    let pkg = try!(source.download(pkgid));
+                    let pkg = try!(source.download(pkgid, config));
                     Ok((pkg, Box::new(source)))
                 }
                 None => {
index 131b93825db8c414eed214de6c79f4f70b20f60e..488fa9853a148d16553121e438f670ad128a346e 100644 (file)
@@ -52,7 +52,7 @@ fn metadata_full(ws: &Workspace,
     let (packages, resolve) = deps;
 
     let packages = try!(packages.package_ids()
-                                .map(|i| packages.get(i).map(|p| p.clone()))
+                                .map(|i| packages.get(i, ws.config()).map(|p| p.clone()))
                                 .collect());
 
     Ok(ExportInfo {
index 7cbd2149fe4671d175042933d371bbf2a0e47ddf..5ff2a6c8fee202a4a4aae9d05168fe0501cece2f 100644 (file)
@@ -156,7 +156,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                 }
             }));
         }
-        for dep in try!(self.dep_targets(&unit)) {
+        for dep in try!(self.dep_targets(&unit, self.config)) {
             try!(self.visit_crate_type(&dep, crate_types));
         }
         Ok(())
@@ -251,7 +251,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         for unit in units {
             try!(self.walk_used_in_plugin_map(unit,
                                               unit.target.for_host(),
-                                              &mut visited));
+                                              &mut visited,
+                                              self.config));
         }
         Ok(())
     }
@@ -259,7 +260,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
     fn walk_used_in_plugin_map(&mut self,
                                unit: &Unit<'a>,
                                is_plugin: bool,
-                               visited: &mut HashSet<(Unit<'a>, bool)>)
+                               visited: &mut HashSet<(Unit<'a>, bool)>,
+                               config: &Config)
                                -> CargoResult<()> {
         if !visited.insert((*unit, is_plugin)) {
             return Ok(())
@@ -267,10 +269,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         if is_plugin {
             self.used_in_plugin.insert(*unit);
         }
-        for unit in try!(self.dep_targets(unit)) {
+        for unit in try!(self.dep_targets(unit, config)) {
             try!(self.walk_used_in_plugin_map(&unit,
                                               is_plugin || unit.target.for_host(),
-                                              visited));
+                                              visited,
+                                              config));
         }
         Ok(())
     }
@@ -443,11 +446,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
 
     /// For a package, return all targets which are registered as dependencies
     /// for that package.
-    pub fn dep_targets(&self, unit: &Unit<'a>) -> CargoResult<Vec<Unit<'a>>> {
+    pub fn dep_targets(&self, unit: &Unit<'a>, config: &Config) -> CargoResult<Vec<Unit<'a>>> {
         if unit.profile.run_custom_build {
             return self.dep_run_custom_build(unit)
         } else if unit.profile.doc {
-            return self.doc_deps(unit);
+            return self.doc_deps(unit, config);
         }
 
         let id = unit.pkg.package_id();
@@ -490,7 +493,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                 true
             })
         }).filter_map(|id| {
-            match self.get_package(id) {
+            match self.get_package(id, config) {
                 Ok(pkg) => {
                     pkg.targets().iter().find(|t| t.is_lib()).map(|t| {
                         Ok(Unit {
@@ -564,7 +567,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             profile: &self.profiles.dev,
             ..*unit
         };
-        let deps = try!(self.dep_targets(&tmp));
+        let deps = try!(self.dep_targets(&tmp, self.config));
         Ok(deps.iter().filter_map(|unit| {
             if !unit.target.linkable() || unit.pkg.manifest().links().is_none() {
                 return None
@@ -578,7 +581,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
     }
 
     /// Returns the dependencies necessary to document a package
-    fn doc_deps(&self, unit: &Unit<'a>) -> CargoResult<Vec<Unit<'a>>> {
+    fn doc_deps(&self, unit: &Unit<'a>, config: &Config) -> CargoResult<Vec<Unit<'a>>> {
         let deps = self.resolve.deps(unit.pkg.package_id()).filter(|dep| {
             unit.pkg.dependencies().iter().filter(|d| {
                 d.name() == dep.name()
@@ -590,7 +593,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                 }
             })
         }).map(|dep| {
-            self.get_package(dep)
+            self.get_package(dep, config)
         });
 
         // To document a library, we depend on dependencies actually being
@@ -673,8 +676,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
     }
 
     /// Gets a package for the given package id.
-    pub fn get_package(&self, id: &PackageId) -> CargoResult<&'a Package> {
-        self.packages.get(id)
+    pub fn get_package(&self, id: &PackageId, config: &Config) -> CargoResult<&'a Package> {
+        self.packages.get(id, config)
     }
 
     /// Get the user-specified linker for a particular host or target
index 5a15e85a853af264e18350ffc4e99cd78e95f31e..c78d067d6181c1bf698d5698f6ccece6f4a1abec 100644 (file)
@@ -413,7 +413,7 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>,
         if !unit.target.is_custom_build() && unit.pkg.has_custom_build() {
             add_to_link(&mut ret, unit.pkg.package_id(), unit.kind);
         }
-        for unit in try!(cx.dep_targets(unit)).iter() {
+        for unit in try!(cx.dep_targets(unit, cx.config)).iter() {
             let dep_scripts = try!(build(out, cx, unit));
 
             if unit.target.for_host() {
index 702deb5f863c5c5f900c548f484f0027e344c510..a24d7ad2b6d05137ade58891b1a52662e8a46504 100644 (file)
@@ -345,7 +345,7 @@ fn calculate<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
     // elsewhere. Also skip fingerprints of binaries because they don't actually
     // induce a recompile, they're just dependencies in the sense that they need
     // to be built.
-    let deps = try!(cx.dep_targets(unit));
+    let deps = try!(cx.dep_targets(unit, cx.config));
     let deps = try!(deps.iter().filter(|u| {
         !u.target.is_custom_build() && !u.target.is_bin()
     }).map(|unit| {
index 53bad6b786c602e7a11cfbf904bcf63061eceed4..db359a7345a1212f955cf3288bf53fa17d2cea94 100644 (file)
@@ -323,12 +323,12 @@ impl<'a> Key<'a> {
     fn dependencies<'cfg>(&self, cx: &Context<'a, 'cfg>)
                           -> CargoResult<Vec<Key<'a>>> {
         let unit = Unit {
-            pkg: try!(cx.get_package(self.pkg)),
+            pkg: try!(cx.get_package(self.pkg, cx.config)),
             target: self.target,
             profile: self.profile,
             kind: self.kind,
         };
-        let targets = try!(cx.dep_targets(&unit));
+        let targets = try!(cx.dep_targets(&unit, cx.config));
         Ok(targets.iter().filter_map(|unit| {
             // Binaries aren't actually needed to *compile* tests, just to run
             // them, so we don't include this dependency edge in the job graph.
index 280b6c05df5fcf0b58a704e51f14ab068f416c49..660f517ca8f2b3a0b572ff26b8085eb03f51b672 100644 (file)
@@ -130,7 +130,7 @@ pub fn compile_targets<'a, 'cfg: 'a>(ws: &Workspace<'cfg>,
             if !unit.target.is_lib() { continue }
 
             // Include immediate lib deps as well
-            for unit in try!(cx.dep_targets(unit)).iter() {
+            for unit in try!(cx.dep_targets(unit, cx.config)).iter() {
                 let pkgid = unit.pkg.package_id();
                 if !unit.target.is_lib() { continue }
                 if unit.profile.doc { continue }
@@ -197,7 +197,7 @@ fn compile<'a, 'cfg: 'a>(cx: &mut Context<'a, 'cfg>,
     drop(p);
 
     // Be sure to compile all dependencies of this target as well.
-    for unit in try!(cx.dep_targets(unit)).iter() {
+    for unit in try!(cx.dep_targets(unit, cx.config)).iter() {
         try!(compile(cx, jobs, unit));
     }
     Ok(())
@@ -652,7 +652,7 @@ fn build_deps_args(cmd: &mut CommandPrototype, cx: &Context, unit: &Unit)
         cmd.env("OUT_DIR", &layout.build_out(unit.pkg));
     }
 
-    for unit in try!(cx.dep_targets(unit)).iter() {
+    for unit in try!(cx.dep_targets(unit, cx.config)).iter() {
         if unit.target.linkable() && !unit.profile.doc {
             try!(link_to(cmd, cx, unit));
         }
index af912b0dfba15ae6fab61a4c50a58fbced1dbb94..5f4c1617accd6045fb0e0c476b2f71b6bd5862f5 100644 (file)
@@ -4,19 +4,19 @@ use core::{PackageId, PackageIdSpec, SourceId, Workspace};
 use core::registry::PackageRegistry;
 use core::resolver::{self, Resolve, Method};
 use ops;
-use util::CargoResult;
+use util::{CargoResult, Config};
 
 /// Resolve all dependencies for the specified `package` using the previous
 /// lockfile as a guide if present.
 ///
 /// This function will also write the result of resolution as a new
 /// lockfile.
-pub fn resolve_ws(registry: &mut PackageRegistry, ws: &Workspace)
+pub fn resolve_ws(registry: &mut PackageRegistry, ws: &Workspace, config: &Config)
                    -> CargoResult<Resolve> {
     let prev = try!(ops::load_pkg_lockfile(ws));
     let resolve = try!(resolve_with_previous(registry, ws,
                                              Method::Everything,
-                                             prev.as_ref(), None, &[]));
+                                             prev.as_ref(), None, &[], config));
 
     // Avoid writing a lockfile if we are `cargo install`ing a non local package.
     if ws.current_opt().map(|pkg| pkg.package_id().source_id().is_path()).unwrap_or(true) {
@@ -39,7 +39,8 @@ pub fn resolve_with_previous<'a>(registry: &mut PackageRegistry,
                                  method: Method,
                                  previous: Option<&'a Resolve>,
                                  to_avoid: Option<&HashSet<&'a PackageId>>,
-                                 specs: &[PackageIdSpec])
+                                 specs: &[PackageIdSpec],
+                                 config: &Config)
                                  -> CargoResult<Resolve> {
     // Here we place an artificial limitation that all non-registry sources
     // cannot be locked at more than one revision. This means that if a git
@@ -127,7 +128,7 @@ pub fn resolve_with_previous<'a>(registry: &mut PackageRegistry,
         None => root_replace.to_vec(),
     };
 
-    let mut resolved = try!(resolver::resolve(&summaries, &replace, registry));
+    let mut resolved = try!(resolver::resolve(&summaries, &replace, registry, config));
     if let Some(previous) = previous {
         try!(resolved.merge_from(previous));
     }
index 84a9501a03b59c8d4c7abb176337b6e412b9f291..650a5092413693fa40d94c8c7db8cbfae35cffdd 100644 (file)
@@ -44,7 +44,7 @@ impl<'cfg> Debug for DirectorySource<'cfg> {
 }
 
 impl<'cfg> Registry for DirectorySource<'cfg> {
-    fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+    fn query(&mut self, dep: &Dependency, _config: &Config) -> CargoResult<Vec<Summary>> {
         let packages = self.packages.values().map(|p| &p.0);
         let matches = packages.filter(|pkg| dep.matches(pkg.summary()));
         let summaries = matches.map(|pkg| pkg.summary().clone());
@@ -98,7 +98,7 @@ impl<'cfg> Source for DirectorySource<'cfg> {
         Ok(())
     }
 
-    fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
+    fn download(&mut self, id: &PackageId, _config: &Config) -> CargoResult<Package> {
         self.packages.get(id).map(|p| &p.0).cloned().chain_error(|| {
             human(format!("failed to find package with id: {}", id))
         })
index eeffcb05b724d7e5a7044729c3f6848c4d52aa3f..87e424810a922a104e124c5116a6694b2ea4ddf9 100644 (file)
@@ -114,10 +114,10 @@ impl<'cfg> Debug for GitSource<'cfg> {
 }
 
 impl<'cfg> Registry for GitSource<'cfg> {
-    fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+    fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
         let src = self.path_source.as_mut()
                       .expect("BUG: update() must be called before query()");
-        src.query(dep)
+        src.query(dep, config)
     }
 }
 
@@ -175,12 +175,12 @@ impl<'cfg> Source for GitSource<'cfg> {
         self.path_source.as_mut().unwrap().update()
     }
 
-    fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
+    fn download(&mut self, id: &PackageId, config: &Config) -> CargoResult<Package> {
         trace!("getting packages for package id `{}` from `{:?}`", id,
                self.remote);
         self.path_source.as_mut()
                         .expect("BUG: update() must be called before get()")
-                        .download(id)
+                        .download(id, config)
     }
 
     fn fingerprint(&self, _pkg: &Package) -> CargoResult<String> {
index 052d01c7dab0c755efe172975f6c0d6e5c3ef875..cee7f6cf3f10d8e9b4751c6fc166b846c815af04 100644 (file)
@@ -310,8 +310,8 @@ impl<'cfg> Debug for PathSource<'cfg> {
 }
 
 impl<'cfg> Registry for PathSource<'cfg> {
-    fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
-        self.packages.query(dep)
+    fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
+        self.packages.query(dep, config)
     }
 }
 
@@ -326,7 +326,7 @@ impl<'cfg> Source for PathSource<'cfg> {
         Ok(())
     }
 
-    fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
+    fn download(&mut self, id: &PackageId, _config: &Config) -> CargoResult<Package> {
         trace!("getting packages; id={}", id);
 
         let pkg = self.packages.iter().find(|pkg| pkg.package_id() == id);
index 5f27b4b2a4f8b36cafc46309b270c160158fe68a..9d50b4f75bbd3417c5697f7a5db7c861bf11c003 100644 (file)
@@ -35,13 +35,13 @@ impl<'cfg> RegistryIndex<'cfg> {
     }
 
     /// Return the hash listed for a specified PackageId.
-    pub fn hash(&mut self, pkg: &PackageId) -> CargoResult<String> {
+    pub fn hash(&mut self, pkg: &PackageId, config: &Config) -> CargoResult<String> {
         let key = (pkg.name().to_string(), pkg.version().to_string());
         if let Some(s) = self.hashes.get(&key) {
             return Ok(s.clone())
         }
         // Ok, we're missing the key, so parse the index file to load it.
-        try!(self.summaries(pkg.name()));
+        try!(self.summaries(pkg.name(), config));
         self.hashes.get(&key).chain_error(|| {
             internal(format!("no hash listed for {}", pkg))
         }).map(|s| s.clone())
@@ -51,11 +51,11 @@ impl<'cfg> RegistryIndex<'cfg> {
     ///
     /// Returns a list of pairs of (summary, yanked) for the package name
     /// specified.
-    pub fn summaries(&mut self, name: &str) -> CargoResult<&Vec<(Summary, bool)>> {
+    pub fn summaries(&mut self, name: &str, config: &Config) -> CargoResult<&Vec<(Summary, bool)>> {
         if self.cache.contains_key(name) {
             return Ok(self.cache.get(name).unwrap());
         }
-        let summaries = try!(self.load_summaries(name));
+        let summaries = try!(self.load_summaries(name, config));
         let summaries = summaries.into_iter().filter(|summary| {
             summary.0.package_id().name() == name
         }).collect();
@@ -63,7 +63,7 @@ impl<'cfg> RegistryIndex<'cfg> {
         Ok(self.cache.get(name).unwrap())
     }
 
-    fn load_summaries(&mut self, name: &str) -> CargoResult<Vec<(Summary, bool)>> {
+    fn load_summaries(&mut self, name: &str, config: &Config) -> CargoResult<Vec<(Summary, bool)>> {
         let (path, _lock) = if self.locked {
             let lock = self.path.open_ro(Path::new(INDEX_LOCK),
                                          self.config,
@@ -97,7 +97,7 @@ impl<'cfg> RegistryIndex<'cfg> {
                 try!(f.read_to_string(&mut contents));
                 let ret: CargoResult<Vec<(Summary, bool)>>;
                 ret = contents.lines().filter(|l| l.trim().len() > 0)
-                              .map(|l| self.parse_registry_package(l))
+                              .map(|l| self.parse_registry_package(l, config))
                               .collect();
                 ret.chain_error(|| {
                     internal(format!("failed to parse registry's information \
@@ -112,14 +112,14 @@ impl<'cfg> RegistryIndex<'cfg> {
     /// package.
     ///
     /// The returned boolean is whether or not the summary has been yanked.
-    fn parse_registry_package(&mut self, line: &str)
+    fn parse_registry_package(&mut self, line: &str, config: &Config)
                               -> CargoResult<(Summary, bool)> {
         let RegistryPackage {
             name, vers, cksum, deps, features, yanked
         } = try!(json::decode::<RegistryPackage>(line));
         let pkgid = try!(PackageId::new(&name, &vers, &self.source_id));
         let deps: CargoResult<Vec<Dependency>> = deps.into_iter().map(|dep| {
-            self.parse_registry_dependency(dep)
+            self.parse_registry_dependency(dep, config)
         }).collect();
         let deps = try!(deps);
         let summary = try!(Summary::new(pkgid, deps, features));
@@ -129,14 +129,14 @@ impl<'cfg> RegistryIndex<'cfg> {
     }
 
     /// Converts an encoded dependency in the registry to a cargo dependency
-    fn parse_registry_dependency(&self, dep: RegistryDependency)
+    fn parse_registry_dependency(&self, dep: RegistryDependency, config: &Config)
                                  -> CargoResult<Dependency> {
         let RegistryDependency {
             name, req, features, optional, default_features, target, kind
         } = dep;
 
         let dep = try!(DependencyInner::parse(&name, Some(&req),
-                                              &self.source_id));
+                                              &self.source_id, config));
         let kind = match kind.as_ref().map(|s| &s[..]).unwrap_or("") {
             "dev" => Kind::Development,
             "build" => Kind::Build,
@@ -165,9 +165,9 @@ impl<'cfg> RegistryIndex<'cfg> {
 }
 
 impl<'cfg> Registry for RegistryIndex<'cfg> {
-    fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+    fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
         let mut summaries = {
-            let summaries = try!(self.summaries(dep.name()));
+            let summaries = try!(self.summaries(dep.name(), config));
             summaries.iter().filter(|&&(_, yanked)| {
                 dep.source_id().precise().is_some() || !yanked
             }).map(|s| s.0.clone()).collect::<Vec<_>>()
@@ -187,7 +187,7 @@ impl<'cfg> Registry for RegistryIndex<'cfg> {
                 _ => true,
             }
         });
-        summaries.query(dep)
+        summaries.query(dep, config)
     }
 
     fn supports_checksums(&self) -> bool {
index 3a1babafb040de2502269a12055f6aabce4eb296..2b959b163f267a7a617f3f929d9d1741e6f12db6 100644 (file)
@@ -317,18 +317,18 @@ impl<'cfg> RegistrySource<'cfg> {
 }
 
 impl<'cfg> Registry for RegistrySource<'cfg> {
-    fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+    fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
         // If this is a precise dependency, then it came from a lockfile and in
         // theory the registry is known to contain this version. If, however, we
         // come back with no summaries, then our registry may need to be
         // updated, so we fall back to performing a lazy update.
         if dep.source_id().precise().is_some() && !self.updated {
-            if try!(self.index.query(dep)).is_empty() {
+            if try!(self.index.query(dep, config)).is_empty() {
                 try!(self.do_update());
             }
         }
 
-        self.index.query(dep)
+        self.index.query(dep, config)
     }
 
     fn supports_checksums(&self) -> bool {
@@ -351,15 +351,15 @@ impl<'cfg> Source for RegistrySource<'cfg> {
         Ok(())
     }
 
-    fn download(&mut self, package: &PackageId) -> CargoResult<Package> {
-        let hash = try!(self.index.hash(package));
+    fn download(&mut self, package: &PackageId, config: &Config) -> CargoResult<Package> {
+        let hash = try!(self.index.hash(package, config));
         let path = try!(self.ops.download(package, &hash));
         let path = try!(self.unpack_package(package, &path).chain_error(|| {
             internal(format!("failed to unpack package `{}`", package))
         }));
         let mut src = PathSource::new(&path, &self.source_id, self.config);
         try!(src.update());
-        src.download(package)
+        src.download(package, config)
     }
 
     fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {
index 7fb95bdf6c87ee9aca2f20c980bcc58ac8ad4da6..ad94d101cb8077d9f8aedfccc774444dd620a18c 100644 (file)
@@ -1,5 +1,5 @@
 use core::{Source, Registry, PackageId, Package, Dependency, Summary, SourceId};
-use util::{CargoResult, ChainError, human};
+use util::{CargoResult, ChainError, human, Config};
 
 pub struct ReplacedSource<'cfg> {
     to_replace: SourceId,
@@ -20,9 +20,9 @@ impl<'cfg> ReplacedSource<'cfg> {
 }
 
 impl<'cfg> Registry for ReplacedSource<'cfg> {
-    fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+    fn query(&mut self, dep: &Dependency, config: &Config) -> CargoResult<Vec<Summary>> {
         let dep = dep.clone().map_source(&self.to_replace, &self.replace_with);
-        let ret = try!(self.inner.query(&dep).chain_error(|| {
+        let ret = try!(self.inner.query(&dep, config).chain_error(|| {
             human(format!("failed to query replaced source `{}`",
                           self.to_replace))
         }));
@@ -40,9 +40,9 @@ impl<'cfg> Source for ReplacedSource<'cfg> {
         })
     }
 
-    fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
+    fn download(&mut self, id: &PackageId, config: &Config) -> CargoResult<Package> {
         let id = id.with_source_id(&self.replace_with);
-        let pkg = try!(self.inner.download(&id).chain_error(|| {
+        let pkg = try!(self.inner.download(&id, config).chain_error(|| {
             human(format!("failed to download replaced source `{}`",
                           self.to_replace))
         }));
index a051a2836b3beae49e0e13d9e3859e1371009aa8..06a169bed58ae8335b2a1520c2c8d8dacb83769d 100644 (file)
@@ -883,7 +883,7 @@ impl TomlDependency {
         };
 
         let version = details.version.as_ref().map(|v| &v[..]);
-        let mut dep = try!(DependencyInner::parse(name, version, &new_source_id));
+        let mut dep = try!(DependencyInner::parse(name, version, &new_source_id, cx.config));
         dep = dep.set_features(details.features.unwrap_or(Vec::new()))
                  .set_default_features(details.default_features.unwrap_or(true))
                  .set_optional(details.optional.unwrap_or(false))
index 9e30c0028600b6e955cc5e189cf9c4c185bdbc13..8ed295e91a8f1e659fffd98257cf7ef674803328 100644 (file)
@@ -10,17 +10,19 @@ use hamcrest::{assert_that, equal_to, contains};
 use cargo::core::source::{SourceId, GitReference};
 use cargo::core::dependency::Kind::{self, Development};
 use cargo::core::{Dependency, PackageId, Summary, Registry};
-use cargo::util::{CargoResult, ToUrl};
+use cargo::util::{CargoResult, ToUrl, Config};
 use cargo::core::resolver::{self, Method};
 
 fn resolve<R: Registry>(pkg: PackageId, deps: Vec<Dependency>,
                         registry: &mut R)
                         -> CargoResult<Vec<PackageId>> {
+    let config = Config::default().unwrap();
     let summary = Summary::new(pkg.clone(), deps, HashMap::new()).unwrap();
     let method = Method::Everything;
     Ok(try!(resolver::resolve(&[(summary, method)],
                               &[],
-                              registry)).iter().map(|p| {
+                              registry,
+                              &config)).iter().map(|p| {
         p.clone()
     }).collect())
 }
@@ -33,7 +35,8 @@ impl ToDep for &'static str {
     fn to_dep(self) -> Dependency {
         let url = "http://example.com".to_url().unwrap();
         let source_id = SourceId::for_registry(&url);
-        Dependency::parse(self, Some("1.0.0"), &source_id).unwrap()
+        let config = Config::default().unwrap();
+        Dependency::parse(self, Some("1.0.0"), &source_id, &config).unwrap()
     }
 }
 
@@ -101,14 +104,16 @@ fn dep(name: &str) -> Dependency { dep_req(name, "1.0.0") }
 fn dep_req(name: &str, req: &str) -> Dependency {
     let url = "http://example.com".to_url().unwrap();
     let source_id = SourceId::for_registry(&url);
-    Dependency::parse(name, Some(req), &source_id).unwrap()
+    let config = Config::default().unwrap();
+    Dependency::parse(name, Some(req), &source_id, &config).unwrap()
 }
 
 fn dep_loc(name: &str, location: &str) -> Dependency {
     let url = location.to_url().unwrap();
     let master = GitReference::Branch("master".to_string());
     let source_id = SourceId::for_git(&url, master);
-    Dependency::parse(name, Some("1.0.0"), &source_id).unwrap()
+    let config = Config::default().unwrap();
+    Dependency::parse(name, Some("1.0.0"), &source_id, &config).unwrap()
 }
 fn dep_kind(name: &str, kind: Kind) -> Dependency {
     dep(name).clone_inner().set_kind(kind).into_dependency()